/* Copyright (c) 2011 by Mani Brundha Kattamuri, Haritha Subramanyam
 *
 * Project Info:  http://code.google.com/p/andriod-travelapp-csc780/wiki/Design
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 */
package com.example.TravelApp.search.common;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * This class makes use of the shared preferences provided by android It
 * contains static methods that can be used to save a string object into shared
 * preferences file, to load a string from the preferences file and to remove an
 * entry from shared preferences.
 */
public class PlacesSharedPreference {

	private static final String PREFIX = "storetalli";

	/**
	 * Saves a string object into the shared preference file. First retrieves
	 * the shared preference file and then puts the string into the file with a
	 * unique preference name.
	 * 
	 * @param c
	 *            - current base context of the activity
	 * @param prefName
	 *            - the preference name
	 * @param object
	 *            - object to be stored
	 */
	public static void saveStringObject(Context c, String prefName,
			String object) {
		SharedPreferences settings = c.getSharedPreferences(prefName, 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.clear();
		editor.putString(PlacesSharedPreference.PREFIX, object);
		editor.commit();
	}

	/**
	 * Retrieves the string from shared preference
	 * 
	 * @param c
	 *            - current base context of the activity
	 * @param prefName
	 *            - the preference name
	 * @param object
	 *            - String object
	 */
	public static String loadStringbject(Context c, String prefName) {
		SharedPreferences settings = c.getSharedPreferences(prefName, 0);
		return (settings.getString(PlacesSharedPreference.PREFIX, ""));
	}

	/**
	 * Removes the specified shared preference
	 * 
	 * @param c
	 *            - current base context of the activity
	 * @param prefName
	 *            - the preference name
	 */
	public static void remove(Context c, String prefName) {
		SharedPreferences settings = c.getSharedPreferences(prefName, 0);
		if (settings.contains(PlacesSharedPreference.PREFIX)) {
			SharedPreferences.Editor editor = settings.edit();
			editor.remove(PlacesSharedPreference.PREFIX);
			editor.commit();
		}
	}

}
